package com.hj.aimin.auth.Controller;


import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hj.aimin.auth.Service.UserService;
import com.hj.aimin.auth.common.Result;
import com.hj.aimin.auth.dto.UserDto;
import com.hj.aimin.auth.entity.User;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/test")
@RequiredArgsConstructor
public class TestController {

    private final UserService userService;

    private final RedisTemplate<String,Object> redisTemplate;

    @GetMapping("/test")
    public String test(){
        return "test";
    }

    @GetMapping("/getAll")
    public String getAll(){
       return userService.list().toString();
    }

    @GetMapping("/join")
    public String getjoin(){
        List<UserDto> join = userService.getJoin();
        join.forEach(System.out::println);
        return "success";
    }

    @GetMapping("/join2")
    public String getjoin2(){
        List<User> byIdDeep = userService.listDeep(Wrappers.emptyWrapper());
        byIdDeep.forEach(System.out::println);
        return "success";
    }

    @GetMapping("/redis")
    public String testRedis(){
        redisTemplate.opsForValue().set("name","aimin");
        return "success";
    }

    @GetMapping("/login")
    public String login(){
        StpUtil.login(1);
        return "login success";
    }

    @GetMapping("/checkLogin")
    public Result<?> checkLogin() {
        try  {
            StpUtil.checkLogin();
            return Result.success("已登录");
        } catch (Exception e) {
            return Result.error(500, "未登录");
        }
    }
}
